<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
    <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
</head>
<script>var index;
</script><body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="customerName" class="layui-form-label">
                <input type="hidden" id="idProAdmin" name="idProAdmin" value="${id}"/>
                <span class="x-red">*</span>客户名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="customerName" name="customerName" lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="customerAddress" class="layui-form-label">
                <span class="x-red">*</span>客户地址
            </label>
            <div class="layui-input-inline">
                <select id="customerProvinces" name="customerProvinces"
                        style="width: 200px;    margin-bottom: 10px;" lay-verify="required" value=""  lay-filter="customerProvinces">
                    <option value="0">请选择省份</option>
                </select>
                <select id="customerCities" name="customerCities"
                        style="width: 200px;    margin-bottom: 10px;" lay-verify="required" value="" lay-filter="customerCities">
                    <option value="0">请选择城市</option>
                </select>
                <select id="customerCounties" name="customerCounties"
                        style="margin-bottom: 10px;" value="" lay-filter="customerCounties">
                    <option value="0">请选择区域</option>
                </select>
                <input type="text" id="customerAddress" name="customerAddress" lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item" >
            <label for="customerContacts" class="layui-form-label">
                <span class="x-red">*</span>联系人
            </label>
            <div class="layui-input-inline">
                <input type="text" id="customerContacts" name="customerContacts" lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="electricTotalCapacity" class="layui-form-label">
                <span class="x-red">*</span>报装总容量
            </label>
            <div class="layui-input-inline">
                <input type="text" id="electricTotalCapacity" name="electricTotalCapacity"
                       lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="customerPhone" class="layui-form-label">
                <span class="x-red">*</span>联系电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="customerPhone" name="customerPhone" lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="voltageGrade" class="layui-form-label">
                <span class="x-red">*</span>电压等级
            </label>
            <div class="layui-input-inline">
                <input type="text" id="voltageGrade" name="voltageGrade" lay-verify="required" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="oneTime" class="layui-form-label">
                <span class="x-red">*</span>第一阶段时长
            </label>
            <div class="layui-input-inline">
                <input type="text" id="oneTime" name="oneTime" lay-verify="number" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="idxOneOperator" class="layui-form-label">
                <span class="x-red">*</span>第一阶段操作人
            </label>
            <div class="layui-input-inline">
                <select id="idxOneOperator" name="idxOneOperator" lay-verify="required">
                    <option>请选择</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <div class="layui-form-item">
            <label for="twoTime" class="layui-form-label">
                <span class="x-red">*</span>第二阶段时长
            </label>
            <div class="layui-input-inline">
                <input type="text" id="twoTime" name="twoTime" lay-verify="number" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="idxTwoOperator" class="layui-form-label" >
                <span class="x-red">*</span>第二阶段操作人
            </label>
            <div class="layui-input-inline">
                <select id="idxTwoOperator" name="idxTwoOperator" lay-verify="required">
                    <option>请选择</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <div class="layui-form-item">
            <label for="threeTime" class="layui-form-label">
                <span class="x-red">*</span>第三阶段时长
            </label>
            <div class="layui-input-inline">
                <input type="text" id="threeTime" name="threeTime" lay-verify="number" placeholder="请输入"
                       autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="idxThreeOperator" class="layui-form-label">
                <span class="x-red">*</span>第三阶段操作人
            </label>
            <div class="layui-input-inline">
                <select id="idxThreeOperator" name="idxThreeOperator" lay-verify="required">
                    <option>请选择</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>第二阶段流程选择
            </label>
            <div class="layui-input-inline">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 155px;">间隔审批</label>
                    <div class="layui-input-block">

                        <input type="radio" name="funIntervalApprovalState"
                               lay-verify="otherReq" lay-filter="funIntervalApprovalState" value="1" title="是">
                        <input type="radio" name="funIntervalApprovalState"
                               lay-verify="otherReq" lay-filter="funIntervalApprovalState" value="0" title="否" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 155px;">申请双重编号</label>
                    <div class="layui-input-block">
                        <input type="radio" name="funDoubleHeavyState"
                               lay-verify="otherReq" lay-filter="funDoubleHeavyState"  value="1" title="是">
                        <input type="radio" name="funDoubleHeavyState"
                               lay-verify="otherReq" lay-filter="funDoubleHeavyState"  value="0" title="否" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 155px;">告知条形码申请</label>
                    <div class="layui-input-block">
                        <input type="radio" name="funInformState"
                               lay-verify="otherReq" lay-filter="funInformState"  value="1" title="是">
                        <input type="radio" name="funInformState"
                               lay-verify="otherReq" lay-filter="funInformState"  value="0" title="否" >
                    </div>
                </div>
                <!--<div class="layui-form-item">
                    <label class="layui-form-label" style="width: 155px;">告知高可靠性费用收取</label>
                    <div class="layui-input-block">
                        <input type="radio" name="funHighChargeState"
                               lay-verify="otherReq" lay-filter="funHighChargeState"  value="1" title="是">
                        <input type="radio" name="funHighChargeState"
                               lay-verify="otherReq"  lay-filter="funHighChargeState" value="0" title="否" >
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 155px;">保护定值报送</label>
                    <div class="layui-input-block">
                        <input type="radio" name="funFixedValuePresentationState"
                               lay-verify="otherReq" lay-filter="funFixedValuePresentationState" value="1" title="是">
                        <input type="radio" name="funFixedValuePresentationState"
                               lay-verify="otherReq" lay-filter="funFixedValuePresentationState" value="0" title="否" >
                    </div>
                </div>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item" id="submitButton">
            <label for="customerName" class="layui-form-label" >
            </label>
            <button  class="layui-btn" lay-filter="preservation" type=button codeTyle="1" lay-submit="">
                保存
            </button>
            <button  class="layui-btn" lay-filter="preAdd" type=button codeTyle="2" lay-submit="">
                预提交
            </button>
            <button  class="layui-btn" lay-filter="add" type=button codeTyle="3" lay-submit="">
                提交
            </button>
        </div>
        <div class="layui-form-item" id="updateStart">
            <label for="customerName" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="update" onclick="history.go(-1)"  type=button codeTyle="0" lay-submit="">
                返回
            </button>
        </div>
    </form>
</div>
<script>
    var provinces = '';


    layui.use(['form','layer'], function() {
        $ = layui.jquery;
        var form = layui.form
            , layedit = layui.layedit;
        layer = layui.layer,

            //自定义验证规则
        form.verify({
            otherReq: function(value,item){
                var $ = layui.$;
                var verifyName=$(item).attr('name')
                    , verifyType=$(item).attr('type')
                    ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                    ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                    ,isTrue= verifyElem.is(':checked')//是否命中校验
                    ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if(!isTrue || !value) {
                    //定位焦点
                    focusElem.css(verifyType == 'radio' ? {"color": "#FF5722"} : {"border-color": "#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
                        focusElem.css(verifyType == 'radio' ? {"color": ""} : {"border-color": ""});
                    }).focus();
                    return '必填项不能为空';
                }
            }
        });
        if(isNull(provinces)){
            //联动省份
            getAddress(0,"customerProvinces",null);
        }
        //监听级别
        form.on('select(customerProvinces)', function (data) {
            var value = data.value;
            $("#customerProvinces").val(value);
        });

        //联动 城市
        form.on('select(customerProvinces)', function (data) {
            var regionalPId = data.value;
            var param = $("#customerProvinces").val();
            if (regionalPId != '') {
                getAddress(regionalPId,"customerCities",null);
            }
        });
        //监听级别
        form.on('select(customerCities)', function (data) {
            var value = data.value;
            $("#customerCities").val(value);
        });

        //联动 区域
        form.on('select(customerCities)', function (data) {
            var regionalPId = data.value;
            var param = $("#customerCities").val();
            if (regionalPId != '') {
                getAddress(regionalPId,"customerCounties",null);
            }
        });
        //监听级别
        form.on('select(customerCounties)', function (data) {
            var value = data.value;
            $("#customerCounties").val(value);
        });

        //监听级别
        form.on('select(idxOneOperator)', function (data) {
            var value = data.value;
            $("#idxOneOperator").val(value);
        });
        //监听级别
        form.on('select(idxTwoOperator)', function (data) {
            var value = data.value;
            $("#idxTwoOperator").val(value);
        });
        //监听级别
        form.on('select(idxThreeOperator)', function (data) {
            var value = data.value;
            $("#idxThreeOperator").val(value);
        });

        form.on('radio(funIntervalApprovalState)', function (data) {
            $("input[name='funIntervalApprovalState']").val(data.value);
        })
        form.on('radio(funDoubleHeavyState)', function (data) {
            $("input[name='funDoubleHeavyState']").val(data.value);
        })
        form.on('radio(funInformState)', function (data) {
            $("input[name='funInformState']").val(data.value);
        })
        /*form.on('radio(funHighChargeState)', function (data) {
            $("input[name='funHighChargeState']").val(data.value);
        })*/
        form.on('radio(funFixedValuePresentationState)', function (data) {
            $("input[name='funFixedValuePresentationState']").val(data.value);
        })

        //监听提交
        form.on('submit(add)', function (t) {
            addSubmit(3);
        });

        //监听保存
        form.on('submit(preservation)', function (t) {
            addSubmit(1);
        });

        //监听预提交
        form.on('submit(preAdd)', function (t) {
            addSubmit(2);
        });
    });


    $(function(){
        ajaxFun('get','/pc/project/getProjectInfo',{"idProAdmin":$("#idProAdmin").val()},function(data){
            if(data.code != 0){
                alertFun(data);
            }else{
                if(data.data.status > 1){
                    $("#submitButton").hide();
                    $("#updateStart").show();
                }else{
                    $("#submitButton").show();
                    $("#updateStart").hide();
                }
                provinces = data.data.customerProvinces;
                $("#customerName").val(data.data.customerName);
                //$("#customerProvinces").val(data.data.customerProvinces);
                getAddress(0,"customerProvinces",data.data.customerProvinces);
                //$("#customerCities").val(data.data.customerCities);
                getAddress(data.data.customerProvinces,"customerCities",data.data.customerCities);
                //$("#customerCounties").val(data.data.customerCounties);
                getAddress(data.data.customerCities,"customerCounties",data.data.customerCounties);
                $("#customerAddress").val(data.data.customerAddress);
                $("#customerContacts").val(data.data.customerContacts);
                $("#customerPhone").val(data.data.customerPhone);
                $("#voltageGrade").val(data.data.voltageGrade);
                $("#oneTime").val(data.data.oneTime);
                //$("#idxOneOperator").val(data.data.idxOneOperator);
                getUserList("idxOneOperator",data.data.idxOneOperator);
                //$("#idxTwoOperator").val(data.data.idxTwoOperator);
                getUserList("idxTwoOperator",data.data.idxTwoOperstor);
                //$("#idxThreeOperator").val(data.data.idxThreeOperstor);
                getUserList("idxThreeOperator",data.data.idxThreeOperstor);
                $("#twoTime").val(data.data.twoTime);
                $("#customerName").val(data.data.customerName);
                $("#threeTime").val(data.data.threeTime);
                //$("input[name='funIntervalApprovalState']").val(data.data.funIntervalApprovalState);
                $("input[name=funIntervalApprovalState][value="+data.data.funIntervalApprovalState+"]")
                    .prop("checked","true");
                $("input[name=funDoubleHeavyState][value="+data.data.funDoubleHeavyState+"]")
                    .prop("checked","true");
                $("input[name=funInformState][value="+data.data.funInformState+"]")
                    .prop("checked","true");
                $("input[name=funFixedValuePresentationState][value="+data.data.funFixedValuePresentationState+"]")
                    .prop("checked","true");
                $("#electricTotalCapacity").val(data.data.electricTotalCapacity);
                renderForm();
            }
        })
    })


    function addSubmit(submitState){
        //统计包装容量
        var numberBYQ,capacityBYQ,numberDDJ,capacityDDJ,electricTotalCapacity = 0;
        $(".template").each(function(){
            numberBYQ = $(this).find("input[name=numberBYQ]").val();
            capacityBYQ = $(this).find("input[name=capacityBYQ]").val();

            numberDDJ = $(this).find("input[name=numberDDJ]").val();
            capacityDDJ = $(this).find("input[name=capacityDDJ]").val();

            electricTotalCapacity = electricTotalCapacity + parseInt(numberBYQ) * parseInt(capacityBYQ) +
                parseInt(numberDDJ) * parseInt(capacityDDJ);
        })
        var params = {
            //tcaDescribe : layui.layedit.getContent(index),
            "idProAdmin":$("#idProAdmin").val(),
            "customerName": $("#customerName").val(),
            "customerCities": $("#customerCities").val(),
            "customerProvinces": $("#customerProvinces").val(),
            "customerCounties": $("#customerCounties").val(),
            "customerAddress": $("#customerAddress").val(),
            "customerContacts": $("#customerContacts").val(),
            "customerPhone": $("#customerPhone").val(),
            "voltageGrade": $("#voltageGrade").val(),
            "oneTime": $("#oneTime").val(),
            "idxOneOperator": $("#idxOneOperator").val(),
            "twoTime": $("#twoTime").val(),
            "idxTwoOperator": $("#idxTwoOperator").val(),
            "threeTime": $("#threeTime").val(),
            "idxThreeOperator": $("#idxThreeOperator").val(),
            "funIntervalApprovalState": $("input[name='funIntervalApprovalState']").val(),
            "funDoubleHeavyState": $("input[name='funDoubleHeavyState']").val(),
            "funInformState": $("input[name='funInformState']").val(),
            "funFixedValuePresentationState": $("input[name='funFixedValuePresentationState']").val(),
            "electricTotalCapacity":$("#electricTotalCapacity").val(),
            "submitState":submitState
        }
        if (true) {
            ajaxFun('post','/pc/project/updateProjec',params,function(data){
                if (data.code != 0) {
                    alertFun(data);
                } else {
                    window.location.href = path + "/modules/project/list.html";
                    console.log("success !");
                }
            })
        }
    }
</script></body></html>